 <?php
	/* Functions in this file */
	/**************************/

	// GetBarline($index)
	// GetBarlineAtPosition($position)
	// GetBarlineCount()
	// GetChordText($index)
	// GetChordTextCount()
	// GetDirection($index)
	// GetDirectionCount()
	// GetEndBar()
	// GetExtraSpacing()
	// GetMFCClassName()
	// GetMFCClassSchema()
	// GetPositionSpacing()
	// GetRect()
	// GetRhythmSlash($index)
	// GetRhythmSlashCount()
	// GetRhythmSlashSpacingAbove()
	// GetRhythmSlashSpacingBelow()
	// GetStaff($index)
	// GetStaffCount()
	// GetStartBar()
	// IsValidBarlineIndex($index)
	// IsValidChordTextIndex($index)
	// IsValidDirectionIndex($index)
	// IsValidRhythmSlashIndex($index)
	// IsValidStaffIndex($index)
	// System()
?>
 
<?php
	 
	 
	 
	class System {
		 
		 
		// Default Constants
		//const DEFAULT_RECT = array (0, 0, 0, 0);
		const DEFAULT_POSITION_SPACING = 20;
		const DEFAULT_RHYTHM_SLASH_SPACING_ABOVE = 0;
		const DEFAULT_RHYTHM_SLASH_SPACING_BELOW = 0;
		const DEFAULT_EXTRA_SPACING = 0;
		 
		// Member Variables
		 
		protected $m_rect = array (50, 20, 800, 143);
		protected $m_positionSpacing = self::DEFAULT_POSITION_SPACING;
		protected $m_rhythmSlashSpacingAbove = self::DEFAULT_RHYTHM_SLASH_SPACING_ABOVE;
		protected $m_rhythmSlashSpacingBelow = self::DEFAULT_RHYTHM_SLASH_SPACING_BELOW;
		protected $m_extraSpacing = self::DEFAULT_EXTRA_SPACING;
		 
		 
		 
		public $m_startBar;
		public $m_directionArray = array ();
		public $m_chordTextArray = array ();
		public $m_rhythmSlashArray = array ();
		public $m_staffArray = array ();
		public $m_barlineArray = array ();
		public $m_endBar;
		 
		 
		// MFC Class Functions
		 
		 
		function GetMFCClassName() {
			return "CSection";
		}
		 
		 
		function GetMFCClassSchema() {
			return 1;
		}
		 
		 
		 
		function GetRect() {
			return ($this->m_rect);
		}
		 
		function SetRect($rect) {
			return ($this->m_rect = $rect);
		}
		
		// Position $this->Spacing Functions
		 
		 
		function GetPositionSpacing() {
			return ($this->m_positionSpacing);
		}
		 
		// Rhythm Slash $this->Spacing Above Functions
		 
		 
		function GetRhythmSlashSpacingAbove() {
			return ($this->m_rhythmSlashSpacingAbove);
		}
		 
		// Rhythm Slash $this->Spacing Below Functions
		 
		 
		function GetRhythmSlashSpacingBelow() {
			return ($this->m_rhythmSlashSpacingBelow);
		}
		 
		// Extra $this->Spacing Functions
		 
		 
		function GetExtraSpacing() {
			return ($this->m_extraSpacing);
		}
		 
		// Start Bar Functions
		 
		 
		function GetStartBar() {
			return ($this->m_startBar);
		}
		 
		 
		function & GetStartBarRef() {
			return ($this->m_startBar);
		}
		 
		 
		static function & GetStartBarConstRef() {
			return ($this->m_startBar);
		}
		 
		// Direction Functions
		 
		 
		 
		function IsValidDirectionIndex($index) {
			return ($index < $this->GetDirectionCount());
		}
		 
		 
		function GetDirectionCount() {
			return sizeof($this->m_directionArray);
		}
		 
		 
		 
		function GetDirection($index) {
			if (!$this->IsValidDirectionIndex($index)) return NULL;
			return ($this->m_directionArray[$index]);
		}
		 
		// Chord Text Functions
		 
		 
		 
		function IsValidChordTextIndex($index) {
			return ($index < $this->GetChordTextCount());
		}
		 
		 
		function GetChordTextCount() {
			return sizeof($this->m_chordTextArray);
		}
		 
		 
		 
		function GetChordText($index) {
			if (!$this->IsValidChordTextIndex($index)) return NULL;
			 return ($this->m_chordTextArray[$index]);
		}
		 
		// Rhythm Slash Functions
		 
		 
		 
		function IsValidRhythmSlashIndex($index) {
			return ($index < $this->GetRhythmSlashCount());
		}
		 
		 
		function GetRhythmSlashCount() {
			return sizeof($this->m_rhythmSlashArray);
		}
		 
		 
		 
		function GetRhythmSlash($index) {
			if (!$this->IsValidRhythmSlashIndex($index)) return NULL;
			return ($this->m_rhythmSlashArray[$index]);
		}
		 
		// Staff Functions
		 
		 
		 
		function IsValidStaffIndex($index) {
			return ($index < $this->GetStaffCount());
		}
		 
		 
		function GetStaffCount() {
			return sizeof($this->m_staffArray);
		}
		 
		 
		 
		function GetStaff($index) {
			if (!$this->IsValidStaffIndex($index)) return NULL;
			 return ($this->m_staffArray[$index]);
		}
		 
		// Barline Functions
		 
		 
		 
		function IsValidBarlineIndex($index) {
			return ($index < $this->GetBarlineCount());
		}
		 
		 
		function GetBarlineCount() {
			return sizeof($this->m_barlineArray);
		}
		 
		 
		 
		function GetBarline($index) {
			if (!$this->IsValidBarlineIndex($index)) return NULL;
			 return ($this->m_barlineArray[$index]);
		}
		 
		// End Bar Functions
		 
		 
		function GetEndBar() {
			return ($this->m_endBar);
		}
		 
		 
		function & GetEndBarRef() {
			return ($this->m_endBar);
		}
		 
		 
		static function & GetEndBarConstRef() {
			return ($this->m_endBar);
		}
		 
		 
		 
		// Constructor/Destructor
		 
		 
		 
		function System() {
			
			$this->m_startBar = new Barline ();
			$this->m_endBar = new Barline ();
			
			$this->m_staffArray[0] = new Staff();
			 
		}
		 
		 
		// Serialize Functions
		 
		 
		 
		function DoSerialize(&$stream){
		 
		
			WRITE_MFC_RECT ($stream,$this->m_rect);

			// Note: End bar is stored as a byte; we use Barline class to make it easier for the user
			$endBar = (($this->m_endBar->GetType() << 5) | ($this->m_endBar->GetRepeatCount()));
			
			WRITE_BYTE ($stream,$endBar);
			WRITE_BYTE ($stream,$this->m_positionSpacing);
			WRITE_BYTE ($stream,$this->m_rhythmSlashSpacingAbove);
			WRITE_BYTE ($stream,$this->m_rhythmSlashSpacingBelow);
			WRITE_BYTE ($stream,$this->m_extraSpacing);
			
			$this->m_startBar->DoSerialize($stream);

			$arr = new PowerTabArray ();
			$arr->Serialize($stream,$this->m_directionArray);

			$arr = new PowerTabArray ();
			$arr->Serialize($stream,$this->m_chordTextArray);

			$arr = new PowerTabArray ();
			$arr->Serialize($stream,$this->m_rhythmSlashArray);

			$arr = new PowerTabArray ();
			$arr->Serialize($stream,$this->m_staffArray);

			$arr = new PowerTabArray ();
			$arr->Serialize($stream,$this->m_barlineArray);
			
			unset($arr);

			return 1;
			
		}
		
		 
		 
		function DoDeserialize(&$stream){
		 
		 
			READ_MFC_RECT ($stream,$this->m_rect);
			
			$this->m_startBar = new Barline ();
			$this->m_endBar = new Barline ();
		 
			$endBar = READ_BYTE ($stream);
			$this->m_positionSpacing = READ_BYTE ($stream);
			$this->m_rhythmSlashSpacingAbove = READ_BYTE ($stream);
			$this->m_rhythmSlashSpacingBelow = READ_BYTE ($stream);
			$this->m_extraSpacing = READ_BYTE ($stream);
		
		 
			// Update end bar (using Barline class is easier to use)
			$this->m_endBar->SetBarlineData((($endBar & 0x000000e0) >> 5), ($endBar & 0x0000001f));
		 
			$this->m_startBar->DoDeserialize($stream);
		
			$arr = new PowerTabArray ();
		 	$this->m_directionArray = $arr->DeSerialize($stream , new Direction());
		 
			$arr = new PowerTabArray (); 
			$this->m_chordTextArray = $arr->DeSerialize($stream , new ChordText());
		
			$arr = new PowerTabArray ();	 
			$this->m_rhythmSlashArray = $arr->DeSerialize($stream , new RhythmSlash());
		
		 	$arr = new PowerTabArray ();
			$this->m_staffArray = $arr->DeSerialize($stream , new Staff());
		
		 	$arr = new PowerTabArray ();
			$this->m_barlineArray = $arr->DeSerialize($stream , new Barline());
			
			unset ($arr);
		
		
		}
		
		// Barline Array Functions
		 
		 
		 
		function GetBarlineAtPosition($position) {
			 
			//------Last Checked------//
			// - Jan 26, 2005
			if ($position == 0)
				return $this->m_startBar;
			 
			// Iterate through the barlines
			$barlineIndex = 0;
			$barlineCount = $this->GetBarlineCount();
			for (; $barlineIndex < $barlineCount; $barlineIndex++) {
				 
				$barline = $this->GetBarline($barlineIndex);
				if ($barline != NULL) continue;
				 
				// Found it; return the barline
				if ($barline->GetPosition() == $position)
					return ($barline);
			}
			 
			// Barline not found at $position
			return (NULL);
		}
		 
		 
	}
	 
?>

